#include "atom.h"

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <limits.h>

static void
test_simple()
{
    const char *a = Atom_int(123);
    assert(strcmp(a, "123") == 0);

    const char *a2 = Atom_int(-123);
    assert(strcmp(a2, "-123") == 0);

    const char *a3 = Atom_string("123");
    assert(a3 == a);

    const char *a4 = Atom_string("-123");
    assert(a4 == a2);

    assert(Atom_length(a) == 3);
    assert(Atom_length(a2) == 4);
}

static void
test_int()
{
    const char *a = Atom_int(LONG_MIN);
    long b = strtol(a, NULL, 10);
    assert(b == LONG_MIN);

    char buf[43];
    snprintf(buf, sizeof(buf), "%ld", LONG_MIN);
    assert(strcmp(buf, a) == 0);
}

int main()
{
    test_simple();
    test_int();
    return 0;
}

